Solutions for Comp248 Assignment 1

Question 1 & Question 2

#include 
class Paint
{
public:
	enum { SIZE = 30};
	Paint ()
	{
		for (row = 0; row < SIZE; row++)
			for (col = 0; col < SIZE; col++)
				points[row][col] = ' ';
		row = col = 10;
	}
	void draw  (char c) { points[row][col] = c; }
	void left  (char c) { draw(c); if (col > 0) col--; }
	void right (char c) { draw(c); if (col < SIZE) col++; }
	void up    (char c) { draw(c); if (row > 0) row--; }
	void down  (char c) { draw(c); if (row < SIZE) row++; }
	void print ()
	{
		for (row = 0; row < SIZE; row++)
		{
			for (col = 0; col < SIZE; col++)
				cout << points[row][col];
			cout << endl;
		}
	}
private:
	char points[SIZE][SIZE];
	int row, col;
};
void main ()
{
	Paint p;
	p.right('+');
	p.right('___');
	p.right('+');
	p.right('___');
	p.right('+');
	p.right('___');
	p.right('+');
	p.right('___');
	p.down('+');
	p.down('|');
	p.down('+');
	p.down('|');
	p.down('+');
	p.down('|');
	p.down('+');
	p.down('|');
	p.left('+');
	p.left('___');
	p.left('+');
	p.left('___');
	p.left('+');
	p.left('___');
	p.left('+');
	p.left('___');
	p.up('+');
	p.up('|');
	p.up('+');
	p.up('|');
	p.up('+');
	p.up('|');
	p.up('+');
	p.up('|');
	p.print();
}
/*
          +_+_+_+_+
          |       |
          +       +
          |       |
          +       +
          |       |
          +       +
          |       |
          +_+_+_+_+
Press any key to continue
*/

#include 
class Paint
{
public:
	enum { SIZE = 10 };
	Paint ()
	{
		for (row = 0; row < SIZE; row++)
			for (col = 0; col < SIZE; col++)
				points[row][col] = ' ';
		row = col = 5;
	}
	void draw  (char c) { points[row][col] = c; }
	void left  (char c) { draw(c); if (col > 0) col--; }
	void right (char c) { draw(c); if (col < SIZE) col++; }
	void up    (char c) { draw(c); if (row > 0) row--; }
	void down  (char c) { draw(c); if (row < SIZE) row++; }
	void print ()
	{
		for (row = 0; row < SIZE; row++)
		{
			for (col = 0; col < SIZE; col++)
				cout << points[row][col];
			cout << endl;
		}
	}
private:
	char points[SIZE][SIZE];
	int row, col;
};
void main ()
{
	Paint p;
	p.right('~');
	p.right('-');
	p.down('+');
	p.down('|');
	p.left('+');
	p.left('-');
	p.up('+');
	p.up(' ');	
	p.print();
}
/*
     ~-+
       |
     +-+
Press any key to continue
*/